<template>
  <div class="caseManage">
    <el-tabs v-model="activeName" type="card" class="elTabs">
      <el-tab-pane name="first">
        <div slot="label" class="pageHeader">涉案信访</div>
      </el-tab-pane>
    </el-tabs>

    <div class="container">
      <!-- 搜索查询 -->
      <div class="searchBar" v-show="showSearch">
        <div class="searchForm">
          <el-form
            :model="queryParams"
            ref="queryForm"
            size="small"
            :inline="true"
            v-show="showSearch"
            label-width="68px"
          >
            <el-form-item label="来访姓名" prop="visitingName">
              <el-input
                v-model="queryParams.visitingName"
                placeholder="请输入来访姓名"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="区域" prop="location">
              <el-autocomplete
                class="inline-input"
                v-model="queryParams.location"
                :fetch-suggestions="querySearch"
                placeholder="请输入区域"
                @keyup.enter.native="handleQuery"
                clearable
              ></el-autocomplete>
            </el-form-item>
          </el-form>
        </div>
        <div class="searchButtons">
          <el-button class="searchButton" @click="handleQuery">搜索</el-button>
          <el-button class="resetButton" @click="resetQuery">重置</el-button>
        </div>
      </div>

      <!-- 新增、批量删除、导入、导出 -->
      <div
        class="addDeleteBar"
        v-if="
          checkPermi(['supervision:petition:add', 'supervision:petition:remove'])
        "
      >
        <el-button class="addButton" @click="handleAdd" v-hasPermi="['supervision:petition:add']">新增</el-button>
        <el-button
          @click="handleDelete"
          :class="!multiple ? 'deleteButton' : 'allDeleteButton'"
          :disabled="multiple"
          icon="el-icon-delete"
          v-hasPermi="['supervision:petition:remove']"
        >批量删除</el-button>
      </div>


      <!-- 表单选择清空 -->
      <div class="tableSelectArea">
        <div>
          <div class="iconInfo el-icon-info"></div>
          <span class="infoText">已选择</span>
          <span class="infoText infoActive" v-text="selectedNum"></span>
          <span class="infoText">项</span>
          <span class="infoButton" @click="clearSelect">清空</span>
        </div>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </div>
      <div class="table">
        <el-table
          v-loading="loading"
          :data="petitionList"
          @selection-change="handleSelectionChange"
          ref="multipleTable"
          class="tableArea"
        >
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="姓名" align="center" prop="visitingName" />
          <el-table-column label="受损金额(元)" align="center" prop="damagedAmount" />
          <el-table-column label="区域" align="center" prop="location" />
          <el-table-column label="稳控责任人" align="center" prop="personLiable" />
          <el-table-column label="稳控单位" align="center" prop="controlUnit" />
          <el-table-column label="涉及案件" align="center" prop="caseName"/>
          <el-table-column label="近期信访行为" align="center" prop="petitionBehavior" :show-overflow-tooltip="true"/>
          <el-table-column label="操作" width="200px" fixed="right" align="left">
            <template slot-scope="scope">
              <div class="tableButtonArea">
                <el-button type="text" class="operationButton" @click="handleDetail(scope.row)">详情</el-button>
                <el-button
                  type="text"
                  class="operationButton"
                  @click="handleUpdate(scope.row)"
                  v-hasPermi="['supervision:petition:edit']"
                >修改</el-button>
                <el-button
                  type="text"
                  class="operationButton"
                  @click="handleDelete(scope.row)"
                  v-hasPermi="['supervision:petition:remove']"
                >删除</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

    </div>

    <petition-manage-modal
      ref="petitionManageModal"
      :modalType.sync="modalType"
      :id="id"
      @fatherMethod="fatherMethod"
    ></petition-manage-modal>
    <petitionDetailModal :detailId.sync="detailId"> </petitionDetailModal>

  </div>
</template>

<script>
import {
  listPetition,
  getPetition,
  delPetition,
  addPetition,
  updatePetition,
} from "@/api/warning/petition/petition";

import { listCase } from "@/api/caseManage/case";
import { getChildXzqh } from "@/api/system/dept";

import { fatherMethod } from "@/utils/commonMethods";


import { checkPermi, checkRole } from "@/utils/permission";
import petitionDetailModal from "./components/petitionDetailModal";
import petitionManageModal from "./components/petitionManageModal.vue";
import {MODALTYPE} from "@/utils/variable";

export default {
  name: "Petition",
  components: { petitionDetailModal,petitionManageModal },
  data() {
    return {
      selectedNum: 0,
      modalType: "",
      id: 0,
      activeName: "first",
      // 遮罩层
      loading: true,
      //详情页Id
      detailId: 0,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 涉案信访表格数据
      petitionList: [],
      // 案件选项
      caseOptions: [],
      // 区域选项
      xzqhOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openInfo: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        visitingName: null,
        location: null,
        controlUnit: null,
      },
      // 表单参数
      form: {},
      formInfo: {},
      // 表单校验
      rules: {
        visitingName: [
          { required: true, message: "姓名不能为空", trigger: "blur" },
        ],
        damagedAmount: [
          { required: true, message: "受损金额不能为空", trigger: "blur" },
        ],
        location: [
          { required: true, message: "区域不能为空", trigger: "blur" },
        ],
        personLiable: [
          { required: true, message: "稳控负责人不能为空", trigger: "blur" },
        ],
        controlUnit: [
          { required: true, message: "稳控单位不能为空", trigger: "blur" },
        ],
        caseName: [
          { required: true, message: "涉及案件不能为空", trigger: "blur" },
        ],
        petitionBehavior: [
          { required: true, message: "近期信访行为不能为空", trigger: "blur" },
        ],
      },

      // 提示框
      districts: [],
    };
  },
  created() {
    this.getList();
    // 案件
    listCase().then((response) => {
      this.caseOptions = response.rows;
    });
  },
  mounted() {
    // 区域
    getChildXzqh("321").then((response) => {
      this.districts = response.data;
    });
  },
  methods: {
    fatherMethod,
    checkPermi,
    querySearch(queryString, cb) {
      const results = queryString
        ? this.districts
            .filter(this.createFilter(queryString))
            .map((district) => ({ value: district.qc }))
        : this.districts.map((district) => ({ value: district.qc }));
      cb(results);
    },
    //清空列表选择
    clearSelect() {
      this.$refs.multipleTable.clearSelection();
    },
    createFilter(queryString) {
      return (district) => {
        return (
          district.qc.toLowerCase().indexOf(queryString.toLowerCase()) === 0
        );
      };
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      this.detailId = row.id;
    },
    handleSelect(item) {
      console.log(item);
    },
    // 用于格式化案件映射值
    formatCaseValue(row) {
      let type = this.caseOptions;
      const valueMap = {};
      type.forEach((res) => {
        let label = res.caseName;
        let value = res.id;
        valueMap[value] = label;
      });
      return valueMap[row["caseName"]];
    },
    /** 查询涉案信访列表 */
    getList() {
      this.loading = true;
      listPetition(this.queryParams).then((response) => {
        this.petitionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        visitingName: null,
        damagedAmount: null,
        location: null,
        personLiable: null,
        controlUnit: null,
        caseName: null,
        petitionBehavior: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        isDelect: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.selectedNum = selection.length;
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.modalType = MODALTYPE["新增"];
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.modalType = MODALTYPE["修改"];
      this.id = row.id;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      let num = this.selectedNum;
      if (row.id) {
        num = 1;
      }
      this.$modal
        .confirm("是否确认删除" + num + "条数据")
        .then(function () {
          return delPetition(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "supervision/petition/export",
        {
          ...this.queryParams,
        },
        `petition_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>


<style lang="scss" scoped>
@import "../../../assets/styles/variables.scss";
.caseManage {
  height: 100%;
  .tableFooter {
    text-align: right;
    justify-content: flex-end;
    // margin-top: 25px;
    margin-right: 35px;
    // width: 100%;
    ::v-deep .btn-prev {
      color: #d4d3d3 !important;
      background-color: #fff;
      border: 1px solid #d4d3d3;
    }
    ::v-deep .btn-next {
      color: #d4d3d3 !important;
      background-color: #fff;
      border: 1px solid #d4d3d3;
    }
    ::v-deep .el-pager li {
      background-color: #fff;
      border: 1px solid #d4d3d3;
      font-size: 12px;
      font-family: $font-family;
      font-weight: 400;
      color: #5a5b5d;
    }
  }
  .el-form-item__label {
    font-family: $font-family;
    font-weight: $form-label-font-weight;
    font-size: $form-label-font-size;
    color: $form-label-color;
  }

  .el-input__inner {
    font-size: $form-content-font-size;
    font-family: $font-family;
    font-weight: $form-label-font-weight;
    // color: #AEAFB0;
  }
}
.input {
  width: 150px;
}
::v-deep .el-tabs--card .el-tabs__header {
  background-color: #e4e7ed;
}
::v-deep.el-tabs--card .el-tabs__header .el-tabs__item {
  border-radius: 10px solid black;
  background-color: #fff;
  font-size: 14px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #053ef6;
  line-height: 48px;
  margin-top: 0;
}
</style>

